import 'package:flutter/material.dart';
import 'package:p_location/alarm/res/alarm_vehicle_item.dart';
import 'package:p_location/alarm/ui/detail/vehicle/page_alarm_vehicle_detail.dart';
import 'package:p_location/alarm/utils/trace_judger.dart';
import 'package:p_location/common/widget/tag_view.dart';
import 'package:p_location/map/res/search_person_detail.dart';
import 'package:p_location/utils/navigator_util.dart';

class AlarmVehicleListItem extends StatelessWidget {
  final AlarmVehicleItem _majorHazardObj;

  const AlarmVehicleListItem(this._majorHazardObj);

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        NavigatorUtil.push(
            context,
            PageAlarmVehicleDetail(
                _majorHazardObj,
                _majorHazardObj.id,
                /*_majorHazardObj.alarmType,*/
                _majorHazardObj.alarmTypeName,
                _majorHazardObj.alarmInfo,
                _majorHazardObj.alarmTime,
                _majorHazardObj.status));
      },
      child: Card(
        margin: EdgeInsets.only(left: 10, right: 10, bottom: 10),
        child: Container(
          decoration: BoxDecoration(
              borderRadius: BorderRadius.all(Radius.circular(10))),
          child: Stack(
            alignment: Alignment.centerLeft,
            children: <Widget>[
              Container(
                padding: EdgeInsets.only(left: 0, right: 10),
                margin: EdgeInsets.only(left: 15, top: 15, bottom: 15),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: <Widget>[
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        TagView(
                          _majorHazardObj.alarmTypeName,
                          paddingLeft: 12,
                          paddingBottom: 1,
                          paddingRight: 12,
                          paddingTop: 1,
                          fillColor: Colors.white,
                          strokeColor: _majorHazardObj.status == '报警中'
                              ? Colors.red
                              : Colors.grey,
                          textColor: _majorHazardObj.status == '报警中'
                              ? Colors.red
                              : Colors.grey,
                          radius: 2,
                        ),
                        Text(
                          _majorHazardObj.alarmTime,
                          style: TextStyle(color: Color.fromARGB(99, 0, 0, 0)),
                        )
                      ],
                    ),
                    Container(
                      margin: EdgeInsets.only(top: 5),
                      alignment: Alignment.centerLeft,
                      child: Text(_majorHazardObj.alarmInfo),
                    ),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Text(
                          _majorHazardObj.status,
                          style: TextStyle(
                              fontSize: 12,
                              color: _majorHazardObj.status == '报警中'
                                  ? Colors.red
                                  : Colors.grey),
                        ),
                        Offstage(
                          offstage: _majorHazardObj.status != '报警中' ||  TraceJudger.isHide(_majorHazardObj.alarmTypeName),
                          child: TagView(
                            "追踪",
                            paddingLeft: 15,
                            paddingRight: 15,
                            paddingTop: 1,
                            paddingBottom: 1,
                            radius: 5,
                            strokeColor: Color.fromARGB(255, 56, 160, 253),
                            textColor: Color.fromARGB(255, 56, 160, 253),
                            fillColor: Colors.white,
                            onPress: (){
                              SearchPersonDetail detail = SearchPersonDetail();
                              detail.id = _majorHazardObj.id;
                              detail.name =
                                  _majorHazardObj.carNumber;
                              detail.sn = _majorHazardObj.vehicleSn;
                              detail.typeName = _majorHazardObj.carType;
                              NavigatorUtil.jumpToLocationPageWithTarget(context,detail);
                            },
                          ),
                        )
                      ],
                    )
                  ],
                ),
              )
            ],
          ),
        ),
      ),
    );
  }
}
